package com.hairline.hairlinemarket.controller;

import com.hairline.hairlinemarket.bean.MarketUser;
import com.hairline.hairlinemarket.bean.common.BaseRespVo;
import com.hairline.hairlinemarket.bean.data.OrderIndex;
import com.hairline.hairlinemarket.service.UserService;
import javafx.beans.binding.ObjectExpression;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Author:杨小凯
 * Date:2023-04-23 9:19
 * Description:<描述>
 */
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public BaseRespVo index(){

        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            return BaseRespVo.fail("未登录");
        }
        MarketUser user = (MarketUser) subject.getPrincipal();
        // 返回一个对象
        OrderIndex order = userService.selectData(user.getId());
        HashMap<String, Object> map = new HashMap<>();
        map.put("order", order);
        return BaseRespVo.ok(map);
    }
}
